import request from '@/config/axios'
import { deleteRole } from '../role'

// 设备和角色关联 VO
export interface RoleDeviceVO {
  id: number // 自增编号
  roleId: number // 角色ID
  deviceId: number // 设备ID
}

// 设备和角色关联 API
export const RoleDeviceApi = {
  // 查询设备和角色关联分页
  getRoleDevicePage: async (params: any) => {
    return await request.get({ url: `/system/role-device/page`, params })
  },

  // 查询设备和角色关联详情
  getRoleDevice: async (id: number) => {
    return await request.get({ url: `/system/role-device/get?id=` + id })
  },


  // 新增设备和角色关联（支持批量）
  createRoleDevice: async (data: RoleDeviceVO[]) => {
    return await request.post({ url: `/system/role-device/create`, data })
  },

  // 修改设备和角色关联
  updateRoleDevice: async (data: RoleDeviceVO) => {
    return await request.put({ url: `/system/role-device/update`, data })
  },

  // 删除设备和角色关联
  deleteRoleDevice: async (data: { id: number }) => {
    return await request.delete({ url: `/system/role-device/delete`, data })
  },

  // 导出设备和角色关联 Excel
  exportRoleDevice: async (params) => {
    return await request.download({ url: `/system/role-device/export-excel`, params })
  },
  // 批量删除设备和角色关联
  deleteRoleDeviceBatch: async (ids: number[]) => {
    // 将ids数组转换为多个ids参数
    const params = new URLSearchParams();
    ids.forEach(id => params.append('ids', id.toString()));
    return await request.delete({ url: `/system/role-device/delete-list?${params.toString()}` })
  },
}
